<?php
class tixianControl extends skymvc{
	public $sw;
	public $k;
	public function __construct(){
		parent::__construct();	
		$this->k="tgyuan";
		$this->sw=" k='".$this->k."' AND shopid=".SHOPID;
	}
	
	public function onDefault(){
		$limit=20;
		$where= $this->sw;
		$url=APPTGYUAN."?m=tixian";
		$start=get('per_page','i');
		$option=array(
			"start"=>$start,
			"limit"=>$limit,
			"order"=>"id DESC",
			"where"=>$where,
		);
		$rscount=true;
		$data=M("tixian")->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,$limit,$url);
		$tgyuan=M("tgyuan")->selectRow("id=".SHOPID);	
		$this->smarty->assign(array(
			"data"=>$data,
			"tgyuan"=>$tgyuan
		));
		$this->smarty->display("tixian/index.html");
	}
	
	
	public function onApply(){
		$tgyuan=M("tgyuan")->selectRow("id=".SHOPID);
		$last=M("tixian")->selectRow(array(
			"order"=>"id DESC",
			"where"=>$this->sw,
			"limit"=>1
		));		
		$this->smarty->assign(array(
			"tgyuan"=>$tgyuan,
			"last"=>$last
		));
		$this->smarty->display("tixian/apply.html");
	}
	
	public function onSave(){
		M("tgyuan")->begin();
		$money=post('money');
		if($money<100){
			$this->goAll("提现金额不能小于100元");
		}
		$tgyuan=M("tgyuan")->selectRow("id=".SHOPID);
		if($tgyuan['balance']<$money){
			$this->goAll("提现余额不足");
		}
		
		$data=M("tixian")->postData();
		$data['dateline']=time();
		$data['k']=$this->k;
		$data['shopid']=SHOPID;
		//减少余额
		M('tgyuan')->changenum('balance',-$money,"id=".SHOPID);
		$ntgyuan=M("tgyuan")->selectRow("id=".SHOPID);
		$logdata=array(
				"dateline"=>time(),
				"shopid"=>SHOPID,
				"type_id"=>1,
				"ispay"=>1,
				"money"=>$money1,
				"content"=>"您提现".$money."元,原来".$tgyuan['balance'].",现在".$ntgyuan['balance']."",
			);
		M("tixian")->insert($data);
		M('tgyuan_pay_log')->insert($logdata);
		M("tgyuan")->commit();
		$this->goAll("提现成功，请等待处理",0,0,APPtgyuan."?m=tixian");
	}
	
}

?>